<!--
 * @Descripttion: 图片放大和删除公共组件
 * @version: 
 * @Author: zhangfan
 * @email: 2207044692@qq.com
 * @Date: 2020-07-09 11:16:00
 * @LastEditors: zhangfan
 * @LastEditTime: 2020-08-24 11:48:19
-->
<template>
  <div>
    <ul
      class="clearfix imgStyle"
      :style="{ marginLeft: fileMarginLeft + 'px' }"
    >
      <li class="fl" v-for="(item, index) of upLoadFile" :key="index">
        <el-image
          style="width: 100px; height: 100px"
          :src="item.url"
          :preview-src-list="srcList"
          @click="enlargeImg(index, srcList, oldSrcList)"
        ></el-image>
        <i
          class="icon iconfont iconjian"
          @click="delFile(index, srcList, oldSrcList, upLoadFile)"
          v-if="isDelFile"
        ></i>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'elementImage',
  props: {
    upLoadFile: {
      type: Array,
      default() {
        return []
      },
    },
    srcList: {
      type: Array,
      default() {
        return []
      },
    },
    oldSrcList: {
      type: Array,
      default() {
        return []
      },
    },
    isDelFile: {
      type: Boolean,
      default() {
        return true
      },
    },
    fileMarginLeft: {
      type: String,
    },
  },
  data() {
    return {}
  },
  methods: {
    /**
     * @description: 图片方法
     */
    enlargeImg(index, srcList, oldSrcList) {
      srcList = oldSrcList
      var demo = srcList
      var frontArr = demo.slice(0, index)
      var behindArr = demo.slice(index, demo.length)
      var list = behindArr.concat(frontArr)
      this.$emit('changeSrcList', list)
    },
    /**
     * @description: 删除图片
     */
    delFile(index, srcList, oldSrcList, upLoadFile) {
      upLoadFile.splice(index, 1)
      srcList.splice(index, 1)
      oldSrcList.splice(index, 1)
    },
  },
}
</script>

<style scoped lang="less">
.imgStyle {
  margin-left: 135px;
  li {
    position: relative;
    margin-right: 20px;
    margin-bottom: 20px;
    .iconjian {
      position: absolute;
      right: -6px;
      top: -10px;
      font-size: 20px;
      cursor: pointer;
    }
    .el-image {
      cursor: pointer;
    }
  }
}
</style>
